import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-03-23
 * Time: 16:58
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        if (num == 0) {
            System.out.println(0);
            return;
        }
        boolean flag = false;
        if (num < 0) {
            num = -num;
            flag = true;
        }
        int change = scanner.nextInt();
        StringBuilder sb = new StringBuilder();
        String[] strs = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"};
        while (num != 0) {
            int temp = num % change;
            num /= change;
            sb.append(strs[temp]);
        }
        if (flag) {
            sb.append("-");
        }
        sb.reverse();
        System.out.println(sb.toString());
    }
}
